package com.tvshows.structure.bdd.repositories;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.tvshows.structure.bdd.repositories.interfaces.PropertyRepository;
import com.tvshows.structure.beans.Property;

@Repository( "propertyRepository" )
public class PropertyRepositoryImpl
    implements PropertyRepository
{
    @Autowired
    private SessionFactory sessionFactory;

    @Override
    @Transactional
    public void updateProperty( Property property )
    {
        sessionFactory.getCurrentSession().update( property );
    }

    @Override
    @Transactional
    public Property getProperty()
    {
        return (Property) sessionFactory.getCurrentSession().getNamedQuery( "property.load" ).uniqueResult();
    }

    @Override
    @Transactional
    public void addProperty( Property prop )
    {
        sessionFactory.getCurrentSession().save( prop );
    }

}
